/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.mycompany.delivery.validation;

import com.mycompany.delivery.dto.ContactDTO;
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 *
 * @author mhunek
 */
public class ContactDTOValidation implements ConstraintValidator<ContactDTOConstraint, ContactDTO> {

    @Override
    public void initialize(ContactDTOConstraint constraintAnnotation) {
       
    }

   @Override
    public boolean isValid(ContactDTO contactDTO, ConstraintValidatorContext ctx) {
        //here is the actual validation check
        boolean isValid = !(contactDTO.getName() == null);

        //map the error to the price property
        if ( !isValid ) {
            ctx.disableDefaultConstraintViolation();
            ctx.buildConstraintViolationWithTemplate("chyba")
                    .addPropertyNode("name").addConstraintViolation();
        }
        return isValid;
    }
    
}
